package com.example.schoolexam2.utils;

import com.example.schoolexam2.entity.QuestionCheckd;
import com.example.schoolexam2.entity.QuestionFill;
import com.example.schoolexam2.entity.QuestionJudge;
import com.example.schoolexam2.entity.QuestionRadio;
import com.example.schoolexam2.vo.PageVo;

import java.util.ArrayList;
import java.util.List;

public class PageUtils {
    public  PageVo page(int totalCount, int currentPage, int size){
      try{
              if (size<=0){
                  size=10;
              }else if(size>totalCount){
                  size=totalCount;
              }
              int totalPage=totalCount%size==0?totalCount/size:(totalCount/size)+1; //获取总页数

          //规范当前页
          if (currentPage<=0){
              currentPage=1;
          }else if(currentPage>totalPage){
              currentPage=totalPage;
          }
          int startCount;
          if(currentPage<=2){
              startCount=(currentPage-1)*size;
          }else{
              startCount=(currentPage-1)*size-2;
          }

          return new PageVo(currentPage,totalPage,size,totalCount,null,startCount);
      }catch (Exception e){
          e.printStackTrace();
          return null;
      }
    }

//    public  PageVo pageC(int totalCount,int currentPage, int size){
//       try{
//           if (size<=0){
//               size=10;
//           }else if(size>totalCount){
//               size=totalCount;
//           }
//           int totalPage=totalCount%size==0?totalCount/size:(totalCount/size)+1; //获取总页数
//
//           //规范当前页
//           if (currentPage<=0){
//               currentPage=1;
//           }else if(currentPage>totalPage){
//               currentPage=totalPage;
//           }
//
//           int startCount;
//           if(currentPage<=2){
//               startCount=(currentPage-1)*size;
//           }else{
//               startCount=(currentPage-1)*size-2;
//           }
//           return new PageVo(currentPage,totalPage,size,totalCount,null,startCount);
//       }catch (Exception e){
//           e.printStackTrace();
//           return null;
//       }
//    }
//
//    public  PageVo pageF(int totalCount,int currentPage,int size){
//        try {
//            if (size<=0){
//                size=10;
//            }else if(size>totalCount){
//                size=totalCount;
//            }
//            int totalPage=totalCount%size==0?totalCount/size:(totalCount/size)+1; //获取总页数
//
//            //规范当前页
//            if (currentPage<=0){
//                currentPage=1;
//            }else if(currentPage>totalPage){
//                currentPage=totalPage;
//            }
//            int startCount;
//            if(currentPage<=2){
//                startCount=(currentPage-1)*size;
//            }else{
//                startCount=(currentPage-1)*size-2;
//            }
//            return new PageVo(currentPage,totalPage,size,totalCount,null,startCount);
//        }catch (Exception e){
//            e.printStackTrace();
//            return null;
//        }
//    }
//
//    public  PageVo pageJ(int totalCount,int currentPage, int size){
//       try {
//           if (size<=0){
//               size=10;
//           }else if(size>totalCount){
//               size=totalCount;
//           }
//           int totalPage=totalCount%size==0?totalCount/size:(totalCount/size)+1; //获取总页数
//
//           //规范当前页
//           if (currentPage<=0){
//               currentPage=1;
//           }else if(currentPage>totalPage){
//               currentPage=totalPage;
//           }
//
//           int startCount=(currentPage-1)*size;
//           return new PageVo(currentPage,totalPage,size,totalCount,null,startCount);
//       }catch (Exception e){
//           e.printStackTrace();
//           return null  ;
//       }
//    }

}
